using SS;
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
using TVSBH.dir;
namespace TVSGPP.dir
{
	public class frmProductDesease : Form
	{
		private IContainer components = null;
		private DataGridView dgvList1;
		private Button btnAdd;
		private Button btnDel;
		private DataGridView dgvList2;
		private Button btnClose;
		public Label lblProductName;
		private TabControl tabControl1;
		private TabPage tabPage1;
		private TabPage tabPage2;
		private DataGridViewTextBoxColumn DID;
		private DataGridViewCheckBoxColumn Column3;
		private DataGridViewTextBoxColumn Column2;
		private DataGridViewTextBoxColumn dataGridViewTextBoxColumn1;
		private DataGridViewCheckBoxColumn dataGridViewCheckBoxColumn1;
		private DataGridViewTextBoxColumn dataGridViewTextBoxColumn2;
		private Button btnAddNew;
		private Func objFunc = new Func();
		public int Pid = 0;
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			DataGridViewCellStyle dataGridViewCellStyle = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle3 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle4 = new DataGridViewCellStyle();
			ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(frmProductDesease));
			this.lblProductName = new Label();
			this.dgvList1 = new DataGridView();
			this.DID = new DataGridViewTextBoxColumn();
			this.Column3 = new DataGridViewCheckBoxColumn();
			this.Column2 = new DataGridViewTextBoxColumn();
			this.btnAdd = new Button();
			this.btnDel = new Button();
			this.dgvList2 = new DataGridView();
			this.dataGridViewTextBoxColumn1 = new DataGridViewTextBoxColumn();
			this.dataGridViewCheckBoxColumn1 = new DataGridViewCheckBoxColumn();
			this.dataGridViewTextBoxColumn2 = new DataGridViewTextBoxColumn();
			this.btnClose = new Button();
			this.tabControl1 = new TabControl();
			this.tabPage1 = new TabPage();
			this.tabPage2 = new TabPage();
			this.btnAddNew = new Button();
			((ISupportInitialize)this.dgvList1).BeginInit();
			((ISupportInitialize)this.dgvList2).BeginInit();
			this.tabControl1.SuspendLayout();
			this.tabPage1.SuspendLayout();
			this.tabPage2.SuspendLayout();
			base.SuspendLayout();
			this.lblProductName.BackColor = Color.White;
			this.lblProductName.BorderStyle = BorderStyle.Fixed3D;
			this.lblProductName.Font = new Font("Arial", 9.75f, FontStyle.Bold, GraphicsUnit.Point, 0);
			this.lblProductName.Location = new Point(5, 8);
			this.lblProductName.Name = "lblProductName";
			this.lblProductName.Size = new Size(526, 26);
			this.lblProductName.TabIndex = 0;
			this.lblProductName.Text = "-:-";
			this.lblProductName.TextAlign = ContentAlignment.MiddleCenter;
			this.dgvList1.AllowUserToAddRows = false;
			this.dgvList1.AllowUserToDeleteRows = false;
			this.dgvList1.AllowUserToResizeColumns = false;
			this.dgvList1.AllowUserToResizeRows = false;
			dataGridViewCellStyle.BackColor = Color.FromArgb(192, 255, 255);
			dataGridViewCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvList1.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle;
			this.dgvList1.BackgroundColor = Color.White;
			this.dgvList1.BorderStyle = BorderStyle.Fixed3D;
			this.dgvList1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
			this.dgvList1.Columns.AddRange(new DataGridViewColumn[]
			{
				this.DID,
				this.Column3,
				this.Column2
			});
			this.dgvList1.Dock = DockStyle.Fill;
			this.dgvList1.EnableHeadersVisualStyles = false;
			this.dgvList1.Location = new Point(3, 3);
			this.dgvList1.Name = "dgvList1";
			this.dgvList1.RowHeadersVisible = false;
			dataGridViewCellStyle2.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvList1.RowsDefaultCellStyle = dataGridViewCellStyle2;
			this.dgvList1.RowTemplate.DefaultCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvList1.Size = new Size(492, 303);
			this.dgvList1.TabIndex = 0;
			this.DID.DataPropertyName = "ID";
			this.DID.HeaderText = "DID";
			this.DID.Name = "DID";
			this.DID.Visible = false;
			this.Column3.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Column3.DataPropertyName = "TMP";
			this.Column3.HeaderText = "  -::-";
			this.Column3.MinimumWidth = 40;
			this.Column3.Name = "Column3";
			this.Column3.Width = 40;
			this.Column2.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.Column2.DataPropertyName = "Name";
			this.Column2.HeaderText = "Tên bệnh";
			this.Column2.Name = "Column2";
			this.btnAdd.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnAdd.Location = new Point(29, 360);
			this.btnAdd.Name = "btnAdd";
			this.btnAdd.Size = new Size(90, 30);
			this.btnAdd.TabIndex = 2;
			this.btnAdd.Text = "Gán bệnh";
			this.btnAdd.UseVisualStyleBackColor = true;
			this.btnAdd.Click += new EventHandler(this.btnAdd_Click);
			this.btnDel.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnDel.Location = new Point(121, 360);
			this.btnDel.Name = "btnDel";
			this.btnDel.Size = new Size(90, 30);
			this.btnDel.TabIndex = 3;
			this.btnDel.Text = "Bỏ bệnh";
			this.btnDel.UseVisualStyleBackColor = true;
			this.btnDel.Click += new EventHandler(this.btnDel_Click);
			this.dgvList2.AllowUserToAddRows = false;
			this.dgvList2.AllowUserToDeleteRows = false;
			this.dgvList2.AllowUserToResizeColumns = false;
			this.dgvList2.AllowUserToResizeRows = false;
			dataGridViewCellStyle3.BackColor = Color.FromArgb(192, 255, 255);
			dataGridViewCellStyle3.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvList2.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle3;
			this.dgvList2.BackgroundColor = Color.White;
			this.dgvList2.BorderStyle = BorderStyle.Fixed3D;
			this.dgvList2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
			this.dgvList2.Columns.AddRange(new DataGridViewColumn[]
			{
				this.dataGridViewTextBoxColumn1,
				this.dataGridViewCheckBoxColumn1,
				this.dataGridViewTextBoxColumn2
			});
			this.dgvList2.Dock = DockStyle.Fill;
			this.dgvList2.EnableHeadersVisualStyles = false;
			this.dgvList2.Location = new Point(3, 3);
			this.dgvList2.Name = "dgvList2";
			this.dgvList2.RowHeadersVisible = false;
			dataGridViewCellStyle4.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvList2.RowsDefaultCellStyle = dataGridViewCellStyle4;
			this.dgvList2.RowTemplate.DefaultCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvList2.Size = new Size(492, 303);
			this.dgvList2.TabIndex = 0;
			this.dataGridViewTextBoxColumn1.DataPropertyName = "ID";
			this.dataGridViewTextBoxColumn1.HeaderText = "DID";
			this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1";
			this.dataGridViewTextBoxColumn1.Visible = false;
			this.dataGridViewCheckBoxColumn1.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.dataGridViewCheckBoxColumn1.DataPropertyName = "TMP";
			this.dataGridViewCheckBoxColumn1.HeaderText = "  -::-";
			this.dataGridViewCheckBoxColumn1.MinimumWidth = 40;
			this.dataGridViewCheckBoxColumn1.Name = "dataGridViewCheckBoxColumn1";
			this.dataGridViewCheckBoxColumn1.Width = 40;
			this.dataGridViewTextBoxColumn2.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.dataGridViewTextBoxColumn2.DataPropertyName = "Name";
			this.dataGridViewTextBoxColumn2.HeaderText = "Tên bệnh";
			this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2";
			this.btnClose.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnClose.Location = new Point(441, 360);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new Size(90, 30);
			this.btnClose.TabIndex = 6;
			this.btnClose.Text = "Thoát  [ ESC ]";
			this.btnClose.UseVisualStyleBackColor = true;
			this.btnClose.Click += new EventHandler(this.button1_Click);
			this.tabControl1.Alignment = TabAlignment.Left;
			this.tabControl1.Controls.Add(this.tabPage1);
			this.tabControl1.Controls.Add(this.tabPage2);
			this.tabControl1.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.tabControl1.Location = new Point(5, 37);
			this.tabControl1.Multiline = true;
			this.tabControl1.Name = "tabControl1";
			this.tabControl1.SelectedIndex = 0;
			this.tabControl1.Size = new Size(526, 317);
			this.tabControl1.TabIndex = 7;
			this.tabPage1.Controls.Add(this.dgvList1);
			this.tabPage1.Location = new Point(24, 4);
			this.tabPage1.Name = "tabPage1";
			this.tabPage1.Padding = new Padding(3);
			this.tabPage1.Size = new Size(498, 309);
			this.tabPage1.TabIndex = 0;
			this.tabPage1.Text = "Chữa trị các bệnh";
			this.tabPage1.UseVisualStyleBackColor = true;
			this.tabPage2.Controls.Add(this.dgvList2);
			this.tabPage2.Location = new Point(24, 4);
			this.tabPage2.Name = "tabPage2";
			this.tabPage2.Padding = new Padding(3);
			this.tabPage2.Size = new Size(498, 309);
			this.tabPage2.TabIndex = 1;
			this.tabPage2.Text = "Danh sách bệnh";
			this.tabPage2.UseVisualStyleBackColor = true;
			this.btnAddNew.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnAddNew.Location = new Point(213, 360);
			this.btnAddNew.Name = "btnAddNew";
			this.btnAddNew.Size = new Size(104, 30);
			this.btnAddNew.TabIndex = 8;
			this.btnAddNew.Text = "Thêm mới bệnh";
			this.btnAddNew.UseVisualStyleBackColor = true;
			this.btnAddNew.Click += new EventHandler(this.btnAddNew_Click);
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			base.ClientSize = new Size(534, 396);
			base.Controls.Add(this.btnAddNew);
			base.Controls.Add(this.tabControl1);
			base.Controls.Add(this.btnClose);
			base.Controls.Add(this.btnDel);
			base.Controls.Add(this.btnAdd);
			base.Controls.Add(this.lblProductName);
			this.Cursor = Cursors.Hand;
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			base.KeyPreview = true;
			this.MaximumSize = new Size(550, 430);
			this.MinimumSize = new Size(550, 430);
			base.Name = "frmProductDesease";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = " .: THUỐC - CHUẨN BỆNH";
			base.Load += new EventHandler(this.frmProductDesease_Load);
			base.KeyDown += new KeyEventHandler(this.frmProductDesease_KeyDown);
			((ISupportInitialize)this.dgvList1).EndInit();
			((ISupportInitialize)this.dgvList2).EndInit();
			this.tabControl1.ResumeLayout(false);
			this.tabPage1.ResumeLayout(false);
			this.tabPage2.ResumeLayout(false);
			base.ResumeLayout(false);
		}
		public frmProductDesease()
		{
			this.InitializeComponent();
		}
		private void frmProductDesease_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				base.Close();
			}
		}
		private void button1_Click(object sender, EventArgs e)
		{
			base.Close();
		}
		private void frmProductDesease_Load(object sender, EventArgs e)
		{
			this.getListDesease1();
			this.getListDesease2();
		}
		private void getListDesease1()
		{
			this.dgvList1.AutoGenerateColumns = false;
			this.dgvList1.DataSource = null;
			this.dgvList1.AutoGenerateColumns = false;
			SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
			string cmdText = "SELECT [ID], [Name], CONVERT(bit,0) AS TMP FROM [TabDesease] WHERE [ID] IN (SELECT DID FROM [TabProductDesease] WHERE [Pid] = " + this.Pid + ")";
			SqlCommand selectCommand = new SqlCommand(cmdText, sqlConnection);
			SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(selectCommand);
			DataSet dataSet = new DataSet();
			sqlConnection.Open();
			sqlDataAdapter.Fill(dataSet);
			this.dgvList1.DataSource = dataSet.Tables[0];
			sqlConnection.Close();
			sqlConnection.Dispose();
			sqlDataAdapter.Dispose();
			dataSet.Dispose();
		}
		private void getListDesease2()
		{
			this.dgvList2.AutoGenerateColumns = false;
			this.dgvList2.DataSource = null;
			this.dgvList2.AutoGenerateColumns = false;
			SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
			string cmdText = "SELECT [ID], [Name], CONVERT(bit,0) AS TMP FROM [TabDesease] WHERE [ID] NOT IN (SELECT DID FROM [TabProductDesease] WHERE [Pid] = " + this.Pid + ")";
			SqlCommand selectCommand = new SqlCommand(cmdText, sqlConnection);
			SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(selectCommand);
			DataSet dataSet = new DataSet();
			sqlConnection.Open();
			sqlDataAdapter.Fill(dataSet);
			this.dgvList2.DataSource = dataSet.Tables[0];
			sqlConnection.Close();
			sqlConnection.Dispose();
			sqlDataAdapter.Dispose();
			dataSet.Dispose();
		}
		private void btnAdd_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.dgvList2.RowCount; i++)
			{
				if (this.dgvList2.Rows[i].Cells[1].Value.ToString() == "True")
				{
					this.AddDesease(this.Pid, int.Parse(this.dgvList2.Rows[i].Cells[0].Value.ToString()));
				}
			}
			this.getListDesease1();
			this.getListDesease2();
		}
		public void AddDesease(int Pid, int Desease)
		{
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand(string.Concat(new object[]
				{
					"INSERT INTO [TabProductDesease] VALUES(",
					this.Pid,
					",",
					Desease,
					")"
				}), sqlConnection);
				sqlCommand.ExecuteNonQuery();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
		}
		public void DelDesease(int Pid, int Desease)
		{
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand(string.Concat(new object[]
				{
					"DELETE FROM [TabProductDesease] WHERE [Pid] = ",
					Pid,
					" AND [DID] = ",
					Desease
				}), sqlConnection);
				sqlCommand.ExecuteNonQuery();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
		}
		private void btnDel_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.dgvList1.RowCount; i++)
			{
				if (this.dgvList1.Rows[i].Cells[1].Value.ToString() == "True")
				{
					this.DelDesease(this.Pid, int.Parse(this.dgvList1.Rows[i].Cells[0].Value.ToString()));
				}
			}
			this.getListDesease1();
			this.getListDesease2();
		}
		private void btnAddNew_Click(object sender, EventArgs e)
		{
			new frmDesease
			{
				FormBorderStyle = FormBorderStyle.FixedToolWindow,
				Size = new Size(884, 566),
				MinimumSize = new Size(884, 566),
				MaximumSize = new Size(884, 566),
				WindowState = FormWindowState.Normal
			}.ShowDialog();
			this.getListDesease1();
			this.getListDesease2();
		}
	}
}
